<template>
	<div>
		<div class="classify_con">
			<div class="classify_title">
				<h1>猜你喜欢</h1>
			</div>
            <CommodityList :buttonActive=" isApp ? buttonActive.bind(this,item) : null " v-if="translateDetailData(item)" v-for="(item, index) in  guessYouLike" :key="index" :comInfor="translateDetailData(item)"></CommodityList>
		</div>
	</div>
</template>

<script>
	import CommodityList from "@/components/CommodityList";
	import {translateDetailData} from "@/utils/TranslateDetailDate";
	import { ADD_CAR } from "../../../config/postMessage-types";

	export default {
		props: {
			guessYouLike: {
				type: Array,
				default: () => []
			},
			guessYouLikeid: {
				type: String,
				default: ""
			},
		},
		data() {
			return {
				//标题
				relTitle: "",
				//商品
				goodsNewVO: [],
				guessYouLikedata1:[],
				guessYouLikedata2:[],
			}
		},
		components: {
			CommodityList,
		},
		methods: {
			translateDetailData,
			guessYouLikedata() {
				this.guessYouLikedata1=[]
				for(var i = 0; i < this.guessYouLike.length; i++) {
					if(this.guessYouLike[i].relPosition == "TITLE") {
						this.relTitle = this.guessYouLike[i].relTitle
					}else if(this.guessYouLike[i].relPosition == "GOODS") {
						this.guessYouLike[i].goodsNewVO.mainPic=this.guessYouLike[i].publicityPicture
						this.guessYouLikedata1.push(this.guessYouLike[i].goodsNewVO)
					}
				}
			},
			getdata(){
				if(!this.guessYouLikedata1 || this.guessYouLikedata1.length==0){
					
				}else{
					this.goodsNewVO = this.guessYouLikedata1
				}
			},
			buttonActive(val) {
				//加入购物车
				let titleConfig = JSON.stringify({
					type: ADD_CAR,
					params: {
						page: 'Activity',
						"detailInfo": val,
					}
				});
				window.postMessage(titleConfig);
			}

		},

		created() {

		},
		mounted() {
			this.guessYouLikedata()
			this.getdata()
		},
		computed: {
			guessYouLikeTitle() {
				if(this.guessYouLikeid){
					return this.getCurrentVDO(this.guessYouLikeid).config.guessYouLikeTitle;
				}
			},
			isApp() {
				return window.isApp;
			}
		},
		watch: {
			guessYouLike(data) {
				if(data){
					this.guessYouLikedata()
					this.getdata()
				}
			}
		}
	}
</script>

<style>

</style>